<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>旅游公司</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="renderer" content="webkit|ie-comp|ie-stand">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <meta http-equiv="Cache-Control" content="no-siteapp" />
        <script type="text/javascript" src="./resources/js/jquery-3.4.1.min.js"></script>
        <link rel="stylesheet" href="./resources/css/font.css">
        <link rel="stylesheet" href="./resources/css/xadmin.css">
        <script src="./resources/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./resources/js/xadmin.js"></script>

    </head>
    <script>

        // 获取地址栏参数
        function getQueryVariable(variable)
        {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }

        $(document).ready(function () {
            console.log("页面载入");
            // 获取地址栏id
            var companyId = getQueryVariable("companyId");
            var page = 1;
            routesList(companyId,page);
        });

        function routesList(companyId,page) {
            $.ajax({
                type: "POST",
                dataType: "json",
                data:{"method":"routesListByCompanyId","companyId":companyId,"page":page},
                url:"./routesController",
                success:function (data) {
                    console.log(data);
                    outUser(data);
                }
            });
            return false;
        }

        function outUser(data) {
            var result = "";
            for(var i = 0;i<data["data"].length;i++){

                result+="<tr>";
                result+="<td style='width: 10px;'>"+data["data"][i].touristId+"</td>";
                result+="<td>"+data["data"][i].allSpot+"</td>";
                result+="<td>"+data["data"][i].restaurant+"</td>";
                result+="<td>"+data["data"][i].live+"</td>";
                result+="<td>"+data["data"][i].traffice+"</td>";
                result+="<td>"+data["data"][i].touristTime+"</td>";
                result+="<td>"+data["data"][i].touristPrice+"</td>";
                result+="<td>"+data["data"][i].tel+"</td>";
                result+="<td>"+data["data"][i].nowPeople+"</td>";
                result+="<td>"+data["data"][i].maxPeople+"</td>";
                result+="<td><img src='./"+data["data"][i].routesImg+"'></td>";
                result+="<td class='td-manage'>" +
                    "<a title=\"编辑\"  onclick=\"xadmin.open('编辑','./routesController?method=routesEdit&touristId="+data["data"][i].touristId+"',500,600)\" href=\"javascript:;\">"
                    +"<i class=\"layui-icon\">&#xe642;</i>"+"</a>"
                    +"<a title=\"删除\" onclick=\"routes_del(this,"+data["data"][i].touristId+",'"+data["data"][i].routesImg+"')\"  href=\"javascript:;\">"
                    +"<i class=\"layui-icon\">&#xe640;</i>"+"</a>"
                    +"<a title=\"查看预约客户信息\" onclick=\"xadmin.open('查看预约客户信息','./orderController?method=orderList&touristId="+data["data"][i].touristId+"')\" href=\"javascript:;\">"
                    +"<i class=\"layui-icon\">&#xe63c;</i>"+"</a>"
                    +"</td>";
                result+="</tr>";
            }
            $("#mytbody").html(result);


            /*分页*/
            //字符串存储html文本
            var pagerL ="";
            //当前页
            var nowPage = data["page"];
            for(var i = 1;i<=data["pages"];i++){
                if(i===nowPage){
                    pagerL+="<span class=\"current\">"+i+"</span>"
                }else {
                    pagerL+="<a class=\"num\" href=\"javascript:routesList("+i+")\">"+i+"</a>";
                }
            }
            $("#pagerList").html("<a class=\"prev\" href=\"javascript:routesList(1)\" >&lt;&lt;</a>"
                +pagerL+
                "<a id=\"lastPage\" class=\"next\" href=\"javascript:routesList("+data["pages"]+")\">&gt;&gt;</a>"
            );

            $("#addRoutes").attr("onclick","");

        };

        //查询按钮
        function searchClick() {
            var spotName = $('#spotName').val();
            $.ajax({
                type:"POST",
                data:{"method":"searchRoutes","name":spotName},
                url:"./routesController",
                dataType:"json",
                success:function (data) {
                    console.log("success:"+data);
                    outUser(data);
                },
                error:function(data){
                    console.log("error:"+data);
                }
            });
            return false;
        };
    </script>
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5" method="post">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" id="spotName" name="spotName" placeholder="请输入景点名" autocomplete="off" class="layui-input"></div>
                                <div class="layui-inline layui-show-xs-block">
                                    <%--这里要给button加type=button--%>
                                    <button class="layui-btn" type="button" lay-submit="" lay-filter="search" onclick="searchClick()">
                                        <i class="layui-icon">&#xe615;</i></button>

                                    <div class="layui-inline layui-show-xs-block">
                                        <%--这里要给button加type=button--%>
                                        <button class="layui-btn" title="打印查询线路列表" type="button" lay-submit="" lay-filter="" onclick="window.location.href='./download?method=downCompanyRoutes'" >
                                            <i class="layui-icon">&#xe67d;</i></button>
                                    </div>
                                </div>
                            </form>
                        </div>

                        <div class="layui-card-header">
                            <%--                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>--%>
                            <button class="layui-btn" onclick="xadmin.open('开设线路','./companyControl?method=routesAdd',500,550)"><i class="layui-icon"></i>添加</button>
                                <div class="layui-inline layui-show-xs-block">
                                    <%--这里要给button加type=button--%>
                                    <button class="layui-btn" title="打印本公司开设的线路列表" type="button" lay-submit="" lay-filter="" onclick="window.location.href='./download?method=downCompanyRoutes'" >
                                        <i class="layui-icon">&#xe67d;</i></button>
                                </div>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form"  lay-filter="test">
                                <thead style="text-align: center;">
                                    <tr>
                                        <th>线路ID</th>
                                        <th>旅游景点</th>
                                        <th>餐饮</th>
                                        <th>住宿</th>
                                        <th>交通</th>
                                        <th>时间</th>
                                        <th>费用</th>
                                        <th>负责人电话</th>
                                        <th>预约人数</th>
                                        <th>最多人数</th>
                                        <th>封面图片</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="mytbody"></tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                <div id="pagerList">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
<script>

    /*景点-删除*/
    function routes_del(obj,touristId,rousImg){

        //发异步删除数据
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type:"POST",
                url:"./routesController?method=routesDelete&touristId="+touristId+"&imgUrl="+rousImg ,
                dataType:"json",
                success:function (data) {
                    layer.alert("删除成功",{icon:6},function () {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                        // xadmin.close();
                    });
                },
                error:function (data) {
                    layer.alert("删除失败",{icon:6},function () {
                        xadmin.close();
                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
                }
            });

        });
    }
</script>